package cn.hxzy.zyicon.controller;

import cn.hxzy.zyicon.entity.Icon;
import cn.hxzy.zyicon.entity.IconGroup;
import cn.hxzy.zyicon.entity.Role;
import cn.hxzy.zyicon.entity.User;
import cn.hxzy.zyicon.entity.po.IconGroupPO;
import cn.hxzy.zyicon.entity.po.RolePO;
import cn.hxzy.zyicon.entity.vo.PageBean;
import cn.hxzy.zyicon.entity.vo.ReturnBean;
import cn.hxzy.zyicon.service.IconGroupService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("group")
public class IconGroupController {
    @Autowired
    private IconGroupService iconGroupService;


    @PostMapping("list")
    public ReturnBean list(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        PageBean<IconGroup> all = iconGroupService.findAll(new PageBean<IconGroup>(page, size));
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS, all);
    }

    @PostMapping("searchName")
    public ReturnBean searchName(String searchName, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        PageBean<IconGroup> all = iconGroupService.findIconGroupByNameLike(searchName, new PageBean<IconGroup>(page, size));
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS, all);
    }

    @PostMapping("deleteId")
    public ReturnBean deleteId(Integer id) {
        iconGroupService.delete(id);
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS);
    }

    @PostMapping("add")
    public ReturnBean add(IconGroup iconGroup) {
        iconGroupService.save(iconGroup);
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS);
    }
    @PostMapping("findById")
    public ReturnBean findById(Integer id) {
        IconGroup byId = iconGroupService.findById(id);
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS,byId);
    }
    @PostMapping("update")
    public ReturnBean update(IconGroupPO iconGroupPO) {
        IconGroup iconGroup=new IconGroup();
        BeanUtils.copyProperties(iconGroupPO,iconGroup);
        iconGroupService.update(iconGroup);
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS);
    }
    @PostMapping("groupList")
    public ReturnBean groupList(){
        List<IconGroup> all1 = iconGroupService.findAll1();
        return ReturnBean.of(ReturnBean.AnswerCode.SUCCESS,all1);
    }
}
